﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FileStorage.Caching.CacheContainers.ExpireByTime;
using FileStorage.Caching.CacheContainers.NonExpiring;

namespace FileStorage.Caching.CacheContainers
{
    /// <summary>
    /// Factory class that creates (singleton) CacheContainers
    /// </summary>
    public static class CacheContainerFactory
    {
        #region Non expiring cache container 

        private static ICacheContainer _nonExpiringCacheContainer = null;

        public static ICacheContainer CreateNonExpiringCacheContainer()
        {
            if (_nonExpiringCacheContainer == null)
            {
                _nonExpiringCacheContainer = new NeverExpiringCacheContainer();
            }
            return _nonExpiringCacheContainer;             
        }

        #endregion

        #region Expire by time cache container

        private static Dictionary<TimeSpan, ICacheContainer> _expireByTimeCacheContainers = new Dictionary<TimeSpan, ICacheContainer>();

        public static ICacheContainer CreateExpireByTimeCacheContainer(TimeSpan theTimeSpan)
        {
            if (!_expireByTimeCacheContainers.ContainsKey(theTimeSpan))
            {
                _expireByTimeCacheContainers[theTimeSpan] = new ExpireByTimeCacheContainer(theTimeSpan);
            }
            return _expireByTimeCacheContainers[theTimeSpan];
        }

        #endregion
    }
}
